package com.edu.exam.enums.assessment.generation;

import com.edu.exam.enums.core.BaseEnum;

/**
 * 任务状态枚举
 *
 * @author System
 * @version 1.0.0
 */
public enum JobStatus implements BaseEnum {
    PENDING("PENDING", "待执行"),
    RUNNING("RUNNING", "执行中"),
    COMPLETED("COMPLETED", "已完成"),
    FAILED("FAILED", "失败"),
    CANCELLED("CANCELLED", "已取消"),
    PAUSED("PAUSED", "已暂停"),
    TIMEOUT("TIMEOUT", "超时"),
    PARTIAL_COMPLETED("PARTIAL_COMPLETED", "部分完成"),
    WAITING("WAITING", "等待中"),
    RETRYING("RETRYING", "重试中");

    private final String code;
    private final String description;

    JobStatus(String code, String description) {
        this.code = code;
        this.description = description;
    }

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getDescription() {
        return description;
    }

    public static JobStatus fromCode(String code) {
        for (JobStatus status : values()) {
            if (status.getCode().equals(code)) {
                return status;
            }
        }
        throw new IllegalArgumentException("Unknown job status code: " + code);
    }

    @Override
    public String toString() {
        return code + " - " + description;
    }
}
